const WXAPI = require('../../wxapi/main')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    theme: 'light',
    mode: '', // 模式(care：关怀模式)
    companyName: '',
    brandName: '',
    industryName: '',
    isWaring: false,
    errmsg: '',
  },

  onInput(evt) {
    const { value } = evt.detail;
    this.setData({
      companyName: value,
      isWaring: false,
    });
  },
  
  onBrandInput(evt) {
    const { value } = evt.detail;
    this.setData({
      brandName: value,
      isWaring: false,
    });
  },
  onIndustryInput(evt) {
    const { value } = evt.detail;
    this.setData({
      industryName: value,
      isWaring: false,
    });
  },
  onConfirm() {
    let that = this    
    let _companyName = that.data.companyName
    let _brandName = that.data.brandName
    let _industryName = that.data.industryName
    console.log('va ', _companyName, _brandName)
    if (!_companyName ||_companyName.length > 50) {
      this.setData({
        isWaring: true,
        errmsg: '客户名称(全称)格式有误'
      });
      return
    }
    if (!_brandName || _brandName.length > 50) {
      this.setData({
        isWaring: true,
        errmsg: '客户名称(简称)格式有误'
      });
      return
    }
    if (!_industryName || _industryName.length > 50) {
      this.setData({
        isWaring: true,
        errmsg: '行业格式有误'
      });
      return
    }
    let skey = wx.getStorageSync('loginFlag')
    let postData = {skey, companyName: _companyName, brandName: _brandName, industryName: _industryName}
    WXAPI.saveNetwork(postData)
    .then(res => {
      console.log('res ', res)
      if (res.code === 0) {
        console.log('ok')
        wx.navigateTo({
          url: '/pages/my-network/index',
        })
      } else {
        wx.showToast({
          title: res.message,
          icon: 'error'
        })
      }
    })
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})